<!DOCTYPE html>
<html style="width:100%;height:100%;">
<head lang="en">
    <meta charset="UTF-8">
    <title>未识别手机号列表</title>
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/default/easyui.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/color.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/icon.css">
    <link type="text/css" rel="stylesheet" href="/resources/css/yidong.css">
    <script type="text/javascript" src="/resources/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/resources/easyui/plugin/jquery.cookie.js"></script>
    <script type="text/javascript" src="/resources/easyui/plugin/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var pageSize = $.cookie("pageSize");
            if(!pageSize) {
                $.cookie("pageSize", 10, {expires:1});
            }
            loadList($.cookie("pageSize"), 1);
            var pager = $('#theList').datagrid('getPager');
            if(pager){
                $(pager).pagination({
                    onSelectPage:function(pageNumber, pageSize){
                        loadList(pageSize, pageNumber);
                    },
                    onRefresh:function(pageNumber, pageSize){
                        loadList(pageSize, pageNumber);
                    },
                    onChangePageSize:function(pageSize){
                        $.cookie("pageSize", pageSize, {expires:1});
                        loadList(pageSize, 1);
                    }
                })
            }
        });

        function loadList(pageSize, pageNo, successFun) {
            restClient('/rest/otherTel/list', function(data){
                $('#theList').datagrid("loadData", data);
                if(successFun) successFun();
            }, {pageSize:pageSize, pageNo:pageNo});
        }

        function formatInsertOne(value,row,index){
            if(row.noSegment != null) {
                if(row.noSegment){
                    return '<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newOne(' + row.noSegment + ')">添加</a>' +
                            '&nbsp;&nbsp;&nbsp;' +
                            '<a href="javascript:void(0)" class="easyui-linkbutton" plain="true" onclick="deleteOne(' + row.noSegment + ')">删除</a>';
                } else {
                    return row.noSegment;
                }
            }
        }

    </script>
</head>
<body onload="isLogon();" style="width:100%;height:100%;margin: 0;">
<table id="theList" class="easyui-datagrid" style="width:100%;height:100%;"
       pagination="true"
       data-options="pageList:[10,15,20],pageSize:$.cookie('pageSize') ? $.cookie('pageSize') : 10"
       rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="tel" width="80">手机号</th>
        <th field="noSegment" width="50" data-options="formatter:formatInsertOne">操作</th>
    </tr>
    </thead>
</table>

<div id="dlg" class="easyui-dialog" style="width:400px;height:auto;padding:-20px"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" class="easyui-form" method="post" enctype="multipart/form-data">
        <div class="fitem">
            <label>号码区段：</label>
            <input id="noSegment" name="noSegment" class="easyui-textbox easyui-validatebox"
                   required="true" data-options="missingMessage:'该输入项为必输项', editable:false">
        </div>
        <div class="fitem">
            <label>城市：</label>
            <input id="area" name="area" class="easyui-textbox easyui-validatebox"
                   required="true" data-options="missingMessage:'该输入项为必输项'">
        </div>
        <div class="fitem">
            <label>区号：</label>
            <input id="areaNum" name="areaNum" class="easyui-textbox easyui-validatebox"
                   required="true" data-options="missingMessage:'该输入项为必输项'">
        </div>
        <div class="fitem">
            <label>运营商：</label>
            <select id="numType" name="numType" class="easyui-combobox" data-options="editable:false">
                <option value="移动">移动</option>
                <option value="联通">联通</option>
                <option value="电信">电信</option>
            </select>
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveOne()" style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>
<script type="text/javascript">
    var url;
    var successMsg;
    function deleteOne(noSegment) {
        $.messager.confirm('确认','确认要删除【'+noSegment+'】么?',function(r){
            if (r){
                restClient('/rest/otherTel/delete/'+noSegment, function(result){
                    if (result.success){
                        loadList($.cookie("pageSize"), 1, function () {
                            $.messager.show({
                                title: '温馨提醒',
                                msg: '删除成功'
                            });
                        });
                    } else {
                        $.messager.show({
                            title: '温馨提醒',
                            msg: result.msg ? result.msg : result.message
                        });
                    }
                });
            }
        });
    }

    function newOne(noSegment){
        if(noSegment != null) {
            $('#dlg').dialog('open').dialog('setTitle', '新建');
            $('#fm').form('clear');
            $('#noSegment').textbox('setValue', noSegment);
            $('#numType').combobox('setValue', '移动');
            url = '/rest/otherTel/create';
            successMsg = "添加成功";
        }
    }

    function saveOne(){
        if(!$('#fm').form('validate')){
            $.messager.show({
                title: '温馨提醒',
                msg: '请填写必填字段'
            });
            return;
        }
        restClient(url, function (result) {
            if (result.success) {
                $('#dlg').dialog('close');
                loadList($.cookie("pageSize"), 1, function () {
                    $.messager.show({
                        title: '温馨提醒',
                        msg: successMsg
                    });
                });
            } else {
                $.messager.show({
                    title: '温馨提醒',
                    msg: result.msg ? result.msg : result.message
                });
            }
        }, $('#fm').serialize());
    }
</script>
</body>
</html>